<%--
  Created by IntelliJ IDEA.
  Date: 2022/5/13
  Time: 11:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" +request.getServerPort() +
            request.getContextPath() + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <title>Title</title>
</head>
<body>
<input id="PageContext" type="hidden" value="${pageContext.request.contextPath}" />
<!-- 内容主体区域 -->
<div style="float:right">
<button type="button" class="btn btn-outline-primary " data-toggle="modal"
   data-target="#addVetModal" style="cursor: pointer !important;">
    添加兽医信息
</button>
</div>
<div style="padding: 15px;">
    <div class="panel-body">
        <table class="table table-hover">
            <thead>
            <h1></h1>
            <tr>
                <td>编号</td>
                <td>兽医姓名</td>
                <td>专业特长</td>
                <td>备注</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody id="information">
            </tbody>
        </table>
    </div>
</div>
<div class="modal fade" id="addVetModal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="createFileTitle">添加兽医</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form action="${pageContext.request.contextPath}/addVet" method="post">
                    <div class="form-group">
                        <label for="name" class="col-form-label">姓名</label>
                        <input type="text" autofocus class="form-control" id="name" name="name">
                    </div>
                    <div class="form-group">
                        <label for="specialty" class="col-form-label">特长</label>
                        <input type="text" autofocus class="form-control" id="specialty" name="specialty">
                    </div>
                    <div class="form-group">
                        <label for="other" class="col-form-label">备注</label>
                        <input type="text" autofocus class="form-control" id="other" name="other">
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary" id="createFileSureBut">确认添加</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    $(function () {
        LoadCustomerData();
    })
    //ajax请求
    function LoadCustomerData() {
        $.ajax({
            url: $("#PageContext").val()+"/getVets",
            type: "get",
            dataType: "json",
            success: function (data) {
                // console.log(data)
                // alert(data)
                //清除旧的数据
                $("#information").html("");
                //添加新的数据
                $.each(data, function (i, n) {
                    $("#information").append("<tr>")
                        .append("<td>" + n.id + "</td>")
                        .append("<td>" + n.name + "</td>")
                        .append("<td>" + n.specialty + "</td>")
                        .append("<td>" + n.other + "</td>")
                        .append("<td><button onclick='Del("+n.id+")' class='layui-btn layui-btn-sm layui-btn-primary'><i class='layui-icon layui-icon-delete'></i></button></td>")
                        .append("</tr>")
                });
            },
        })
    }
    //ajax 删除请求
    function Del(id){
        var msg = "确认删除？";
        if (confirm(msg)===true){
            // alert(id+"--"+pageNum)
            id=parseInt(id)
            // alert(id)
            $.ajax({
                url: $("#PageContext").val()+"/deleteVet",
                type: "post",
                data : {
                    id:id
                },
                success: function () {
                    //情况旧数据
                    LoadCustomerData();
                    layer.msg('删除成功');
                }
            })
        }else{
            return false;
        }
    }
</script>
</html>
